from django.db import models
from utils.model import BaseModel
from trade.models import Agent
from django.contrib.auth.models import AbstractUser


# Create your models here.

class ReturnFrom(BaseModel):
    """退换货表单"""
    return_id = models.AutoField(primary_key=True, verbose_name="退换货订单id")
    return_num = models.CharField(null=True, blank=True, max_length=50, verbose_name="退货订单号")
    customer = models.ForeignKey(Agent, on_delete=models.CASCADE,
                                 verbose_name='客户')
    delivery_num = models.CharField(max_length=50, null=True, blank=True, verbose_name='发货快递单号')
    # 0-退货 1-换货
    return_type = models.SmallIntegerField(default=0, verbose_name="退换货类型")
    # 0-巨石 1-全电 2-无限续航
    bs_type = models.SmallIntegerField(default=0, verbose_name="公司")
    date = models.DateField(null=True, verbose_name="日期")
    address = models.CharField(max_length=100, null=True, blank=True, verbose_name="退换货地址")
    reason = models.CharField(max_length=100, null=True, blank=True, verbose_name="退换货原因")
    receipt_num = models.CharField(null=True, blank=True, max_length=50, verbose_name="退货快递单号")
    status = models.SmallIntegerField(default=1, verbose_name="状态")
    delivery_status = models.SmallIntegerField(default=0, verbose_name="发货状态")
    review_status = models.SmallIntegerField(default=0, verbose_name="审核状态")

    class Meta:
        db_table = 'tb_return_from'
        verbose_name = '退换货表'
        verbose_name_plural = verbose_name


class ReturnDevice(BaseModel):
    """退换货设备表"""
    id = models.AutoField(primary_key=True)
    device = models.SmallIntegerField(default=0, verbose_name="设备")
    count = models.IntegerField(default=1, verbose_name="设备数量")
    return_from = models.ForeignKey(ReturnFrom, null=True, on_delete=models.CASCADE)
    status = models.SmallIntegerField(default=1, verbose_name="状态")

    class Meta:
        db_table = 'tb_return_device'
        verbose_name = '退换货设备表'
        verbose_name_plural = verbose_name


class ReissuePB(BaseModel):
    """补发充电宝"""
    reissue_id = models.AutoField(primary_key=True, verbose_name="补宝订单id")
    reissue_num = models.CharField(null=True, blank=True, max_length=50, verbose_name="补宝订单号")
    customer = models.ForeignKey(Agent, on_delete=models.CASCADE,
                                 verbose_name='客户')
    date = models.DateField(null=True, verbose_name="日期")
    address = models.CharField(max_length=100, null=True, blank=True, verbose_name="退换货地址")
    count = models.IntegerField(default=1, verbose_name="设备数量")
    # 0-巨石 1-全电 2-无限续航
    bs_type = models.SmallIntegerField(default=0, verbose_name="公司")
    delivery_num = models.CharField(null=True, blank=True, max_length=50, verbose_name="发货快递单号")
    status = models.SmallIntegerField(default=1, verbose_name="状态")
    delivery_status = models.SmallIntegerField(default=0, verbose_name="发货状态")
    review_status = models.SmallIntegerField(default=0, verbose_name="审核状态")

    class Meta:
        db_table = 'tb_reissue'
        verbose_name = '补宝表'
        verbose_name_plural = verbose_name
